package com.longrise.co.ui.mine.adapter;


import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.co.R;
import com.longrise.co.ui.home.model.BindCarInfo;
import com.longrise.co.utils.Constants;
import com.ly.common.baserx.RxBus;
import com.ly.common.commonutils.ImageLoaderUtils;
import com.ly.common.commonutils.StringUtils;
import com.ly.common.commonutils.TimeUtil;

import java.util.List;


/**
 * Created by admin on 2017/2/4.
 */

public class MyCarAdapter extends BaseQuickAdapter<BindCarInfo.ListBean> {

    private Context mContext;

    public MyCarAdapter(Context context, List<BindCarInfo.ListBean> listData) {
        super(R.layout.item_mine_car, listData);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, final BindCarInfo.ListBean data) {

        baseViewHolder.setText(R.id.car_number,  data.getCarno())
                .setOnClickListener(R.id.repair_evaluation, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //认证车辆
                        RxBus.getInstance().post(Constants.RX_EVENT_AUTH_CAR, "1");
                    }
                })
                .setOnClickListener(R.id.repair_detail, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //修改信息
                        RxBus.getInstance().post(Constants.RX_EVENT_MODIFY_CAR, data);
                    }
                })
                .setOnClickListener(R.id.delete_car, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //删除车辆
                        RxBus.getInstance().post(Constants.RX_EVENT_DELETE_CAR, data.getCarid());
                    }
                })
                .setOnClickListener(R.id.car_photo, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        RxBus.getInstance().post(Constants.RX_EVENT_REFRESH_CAR_PHOTO, data.getCarid());
                    }
                });

        ImageView imageView = baseViewHolder.getView(R.id.car_photo);

        if(imageView != null && !StringUtils.isEmpty(data.getCarphoto())) {
            ImageLoaderUtils.display(mContext, imageView, data.getCarphoto());
        }
        if(!"1".equals(data.getIsapprove())) {
            baseViewHolder.setText(R.id.auth_info, "未认证")
                           .setTextColor(R.id.auth_info, Color.parseColor("#fe5c14"))
                           .setVisible(R.id.repair_evaluation, true);

         } else {
            baseViewHolder.setText(R.id.auth_info, "认证日期：" + TimeUtil.getDateYMD(data.getCreatetime()))
                    .setTextColor(R.id.auth_info, Color.parseColor("#666666"))
                    .setVisible(R.id.repair_evaluation, false);
        }

    }


}
